package com.rockxin.cat.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.orhanobut.logger.Logger;
import com.rockxin.cat.R;
import com.rockxin.cat.adapter.BidLogAdapter;
import com.rockxin.cat.base.BaseFragment;
import com.rockxin.cat.bean.BidDetailsBean;
import com.rockxin.cat.bean.BidLogBean;
import com.rockxin.cat.bean.UseBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * A simple {@link Fragment} subclass.
 */
public class BidLogFragment extends BaseFragment {


    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private Unbinder bind;

    private BidLogAdapter mBidLogAdapter;
    private List<BidLogBean> bidLogBeanList;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bidLogBeanList = new ArrayList<>();
    }

    public BidLogFragment() {
    }

    public static BidLogFragment newInstance() {
        Bundle args = new Bundle();
        BidLogFragment fragment = new BidLogFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View mView = inflater.inflate(R.layout.fragment_bid_log, container, false);
        bind = ButterKnife.bind(this, mView);
        initView();
        return mView;
    }

    private void initView() {
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        recyclerView.setHasFixedSize(true);
        mBidLogAdapter = new BidLogAdapter(bidLogBeanList);
        recyclerView.setAdapter(mBidLogAdapter);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        bind.unbind();
    }

    @org.simple.eventbus.Subscriber(tag = "bid_log")
    public void getBidLogEvent(List<BidLogBean> list) {
        Logger.d("getBidLogEvent=====" + list.size());
        bidLogBeanList.clear();
        bidLogBeanList.addAll(list);
        mBidLogAdapter.notifyDataSetChanged();
    }
}
